package fi.foyt.cs.persistence.dao.task;

import javax.persistence.EntityManager;

import fi.foyt.cs.persistence.dao.GenericDAO;
import fi.foyt.cs.persistence.domainmodel.task.TaskGroup;

public class TaskGroupDAO extends GenericDAO<TaskGroup> {

  public TaskGroup create(String name) {
    EntityManager entityManager = getEntityManager();

    entityManager.getTransaction().begin();
    try {
      TaskGroup taskGroup = new TaskGroup();
      taskGroup.setName(name);
      entityManager.persist(taskGroup);
      entityManager.getTransaction().commit();
      return taskGroup;
    } finally {
      if (entityManager.getTransaction().isActive())
        entityManager.getTransaction().rollback();
    }
  }

}
